// import 'package:flutter/material.dart';

// class MessagePage extends StatefulWidget {
//   const MessagePage({Key? key}) : super(key: key);

//   @override
//   _MessagePageState createState() => _MessagePageState();
// }

// class _MessagePageState extends State<MessagePage> {
//   late ThemeData theme;
//   @override
//   Widget build(BuildContext context) {
//     theme = Theme.of(context);
//     return Scaffold(
//         backgroundColor: theme.scaffoldBackgroundColor,
//         // appBar: AppBar(centerTitle: true, title: const Text("Home")),
//         appBar: AppBar(
//           scrolledUnderElevation: 0.0,
//           title: Text(
//             'Message',
//           ),
//         ),
//         body: SafeArea(
//           child: Container(
//             alignment: Alignment.center,
//             child: Text("Message Page"),
//           ),
//         ));
//   }
// }

import 'package:dodoclub/pages/add/add_page.dart';
import 'package:dodoclub/pages/comm/comm_controller.dart';
import 'package:dodoclub/pages/comm/view_page.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class MessagePage extends StatelessWidget {
  MessagePage({super.key});

  final CommController controller = Get.put(CommController());

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    return Scaffold(
      backgroundColor: Color(0xFFf1f2f3),
      appBar: AppBar(
        scrolledUnderElevation: 0.0,
        title: Text(
          'Summary',
        ),
        actions: <Widget>[
          IconButton(
            icon: const Icon(
              Icons.control_point_sharp,
              size: 22,
              // color: Colors.grey,
            ),
            onPressed: () {
              // tagsController.setTagItem(SpinnerItemData(
              //     name: '问升学', result: '问升学', selected: false, isMutex: false));
              //Toast.show("跳转到添加笔记页面", gravity: 1);
              Get.to(AddItemPage());
            },
          )
        ],
      ),
      body: Column(
        children: [
          Expanded(
            child: Obx(() {
              return ListView.builder(
                itemCount: controller.items.length,
                itemBuilder: (context, index) {
                  var item = controller.items[index];

                  return InkWell(
                    onTap: () {
                      //Get.toNamed("/Message/1");
                      Get.to(ViewPage(index: index));
                    },
                    child: Container(
                      margin: (index == 0)
                          ? EdgeInsets.only(top: 8.0, left: 8, right: 8)
                          : EdgeInsets.only(
                              top: 8.0, left: 8, right: 8), // 设置上边距
                      padding: EdgeInsets.all(8.0), // 其他内边距
                      decoration: BoxDecoration(
                        color: Color.fromARGB(255, 197, 245, 168),
                        borderRadius: BorderRadius.circular(8.0),
                      ),
                      child: Container(
                        color: theme.colorScheme.primaryContainer,
                        padding: const EdgeInsets.symmetric(
                            vertical: 12, horizontal: 12),
                        child: Row(children: [
                          Expanded(
                              child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text(
                                item['title'] ?? 'No Title',
                                style: TextStyle(
                                    fontSize: 20, fontWeight: FontWeight.bold),
                              ),
                              Row(
                                children: [
                                  Text(item['date'] ?? 'No Date',
                                      style: TextStyle(
                                          color: Colors.grey.shade500))
                                ],
                              ),
                              Text(
                                item['value'] ?? 'No Value',
                                maxLines: 2,
                                overflow: TextOverflow.ellipsis,
                              )
                            ],
                          )),
                          // Container(
                          //   width: 75,
                          //   height: 75,
                          //   decoration: BoxDecoration(
                          //       borderRadius: BorderRadius.circular(12),
                          //       image: const DecorationImage(
                          //           image: NetworkImage(
                          //               "https://profile-avatar.csdnimg.cn/5b9b486a599e45a7bd8b545652de34c5_xiongxu74110.jpg"))),
                          // )
                        ]),
                      ),
                    ),
                  );
                },
              );
            }),
          ),
          // ElevatedButton(
          //   onPressed: () {
          //     Get.to(AddItemPage());
          //   },
          //   child: Text('Add Item'),
          // ),
        ],
      ),
    );
  }

}
